<template>
<div>
  <el-form ref="form" :model="form" label-width="80px">
    <el-row>


    <el-col :span="12">
    <el-form-item label="用户名">
      <el-input v-model="form.username"></el-input>
    </el-form-item>
    </el-col>
    <el-col :span="12">
    <el-form-item label="用户账号">
      <el-input v-model="form.useraccount"></el-input>
    </el-form-item>
    </el-col>
    <el-col :span="12">
      <el-form-item label="邮箱">
        <el-input v-model="form.email"></el-input>
      </el-form-item>
    </el-col>
    <el-col :span="12">
      <el-form-item label="电话号">
        <el-input v-model="form.phone"></el-input>
      </el-form-item>
    </el-col>

    <el-col :span="24">
      <el-form-item label="详细地址">
        <el-input v-model="form.detailAddress"></el-input>
      </el-form-item>
    </el-col>
      <el-col :span="24">
    <el-form-item label="有效期">
      <el-col :span="11">
        <el-date-picker type="date" placeholder="选择日期" v-model="form.startdate" style="width: 100%;"></el-date-picker>
      </el-col>
      <el-col class="line" :span="2">-</el-col>
      <el-col :span="11">
        <el-date-picker type="date" placeholder="选择日期" v-model="form.enddate" style="width: 100%;"></el-date-picker>
      </el-col>
    </el-form-item>
      </el-col>

    <el-col :span="12">
      <el-form-item label="是否有效">
        <el-radio-group v-model="form.isAvlid">
          <el-radio label="1" value="1">是</el-radio>
          <el-radio label="否0" value="0">否</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-col>
    <el-col :span="12">
      <el-form-item label="角色">
        <el-radio-group v-model="form.isAdmin">
          <el-radio label="1" value="1">管理员</el-radio>
          <el-radio label="0" value="0">普通用户</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-col>
    </el-row>

    <el-form-item style="align-content: center">
      <el-button type="primary" @click="onSubmit">确定</el-button>
      <el-button @click="cancal">  取消</el-button>
    </el-form-item>
  </el-form>
</div>
</template>

<script>
import instance from "../../utils/request";

export default {
props:['dialogVisible'],

  name: "AddUser",
  data() {
    return {
      // props:{dialogVisible},
      // props:['dialogVisible'],
      form: {
        username: '',
        useraccount: '',
        phone: '',
        startdate: '',
        enddate: '',
        isAvlid: '',
        email: '',
        detailAddress: '',
        isAdmin: '',

      }
    }
  },
  methods: {
    onSubmit() {

      instance.post("/user/addUser",this.form).then(res=>{
        alert("添加成功");
        console.log(this.dialogVisible);
        this.$emit('closeDialog');
        // this.getDialog.close();
      }).catch(err=>{
        alert("服务器错误，请联系管理员");
      })
    },
    cancal(){
      this.$emit('closeDialog');
    }
  },

}
</script>

<style scoped>

</style>
